package com.cskaoyan.bean;

import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

@Data
/**
 * 用来返回分页信息
 */
public class BasePageData<T> {
    Integer limit;
    Integer page;
    Integer pages;
    Integer total;
    List<Goods> goods;
    List<Category> filterCategoryList;
    List<T> list;


    /**
     * 通用的返回分页信息
     * @param list
     * @return
     */
    public static <T> BasePageData ok(List<T> list) {
        PageInfo<T> pageInfo = new PageInfo<>(list);

        BasePageData<T> basePageData = new BasePageData<>();
        basePageData.setPage(pageInfo.getPageNum());
        basePageData.setLimit(pageInfo.getPageSize());
        basePageData.setPages(pageInfo.getPages());
        basePageData.setTotal((int) pageInfo.getTotal());
        basePageData.setList(list);

        return basePageData;
    }
    public static <T> BasePageData ok2(List<Goods> list , List<Category> filterCategoryList){
        PageInfo<Goods> pageInfo = new PageInfo<>(list);

        BasePageData<Goods> basePageData = new BasePageData<>();
        basePageData.setPage(pageInfo.getPageNum());
        basePageData.setLimit(pageInfo.getPageSize());
        basePageData.setPages(pageInfo.getPages());
        basePageData.setTotal((int) pageInfo.getTotal());
        basePageData.setFilterCategoryList(filterCategoryList);
        basePageData.setList(list);
        return basePageData;
    }


    public static BasePageData ok1(List<Goods> goods){
        PageInfo<Goods> goodsPageInfo = new PageInfo<>(goods);
        BasePageData<Goods> goodsBasePageData = new BasePageData<>();
        goodsBasePageData.setPage(goodsPageInfo.getPageNum());
        goodsBasePageData.setLimit(goodsPageInfo.getPageSize());
        goodsBasePageData.setPages(goodsPageInfo.getPages());
        goodsBasePageData.setTotal((int) goodsPageInfo.getTotal());
        goodsBasePageData.setList(goods);

        return goodsBasePageData;
    }

    public static BasePageData commentOk(List<Comment> comments){
        PageInfo<Comment> commentPageInfo = new PageInfo<>(comments);
        BasePageData<Comment> commentBasePageData = new BasePageData<>();
        commentBasePageData.setPage(commentPageInfo.getPageNum());
        commentBasePageData.setLimit(commentPageInfo.getPageSize());
        commentBasePageData.setPages(commentPageInfo.getPages());
        commentBasePageData.setTotal((int) commentPageInfo.getTotal());
        commentBasePageData.setList(comments);

        return commentBasePageData;
    }


}
